import os
from typing import AsyncContextManager
import pymysql

# 连接database
conn = pymysql.connect(
    host="146.56.246.145",
    user="spider",
    password="Wqox1Bp5rFZl688KSgPH1vHnqt8s",
    database="cander",
    charset="utf8mb4")

# 得到一个可以执行SQL语句的光标对象
cursor = conn.cursor()  # 执行完毕返回的结果集默认以元组显示
# 得到一个可以执行SQL语句并且将结果作为字典返回的游标
#cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

# 定义要执行的SQL语句
sql = """
update student set name=%s where id=3
"""

# 执行SQL语句
row = cursor.execute(sql, "宋琪")
print(row)
conn.commit()

# res = cursor.fetchall()
# for row in res:
#     print(row)
#     print("id: {}".format(row[0]))
#     print("name: {}".format(row[1]))
#     print("age: {}" .format(row[2]))
#     print("heigth: {}".format(row[3]))
#     print("gender: {}" .format(row[4]))
#     print("hobby: {}" .format(row[5]))
# 关闭光标对象
cursor.close()


# 关闭数据库连接
conn.close()